﻿using UnityEngine;
using System.Collections;

public class KeyPress : MonoBehaviour {

	public KeycodeChange kC;
	public string Num;
	public PuzzleRoomManager puzzleRoomManager;
	public CameraManager cameraManager;

	// Use this for initialization
	void Start () {
		kC = GameObject.Find("KeycodeString").GetComponent<KeycodeChange>();
		puzzleRoomManager = GameObject.Find ("PuzzleRoomManager").GetComponent<PuzzleRoomManager>();
		cameraManager = GameObject.Find(this.name).GetComponent<CameraManager>();
	}
	
	// Update is called once per frame
	void Update () {
		if(Input.GetMouseButtonDown(0))
			if(puzzleRoomManager.puzzleRoomData.Mouse.collider2D.bounds.Intersects(this.collider2D.bounds))
				keyPressed();
	}

	void keyPressed()
	{
		GameObject.Find("MenuManager").GetComponent<MusicManager>().PlaySoundEffect(Resources.Load("SFX/numbpan", typeof(AudioClip)) as AudioClip);
		Debug.Log("Clicked!");
		if(Num != "" && Num != "a" && Num != "b") //--check if null, a, or b
			kC.addNum(Num); //--adds the number
		else if(Num == "a") //--checks if OK button
			kC.checkKeycode();
		else if(Num == "b")
			kC.removeLastKeycode();
		else
		{
			puzzleRoomManager.mouseActive = false;
			cameraManager.changeCamera(cameraManager.setCamInd);
		}
	}
}
